package com.sherlockHolmes.init.base.result;

import java.util.HashMap;

public class Ajax extends HashMap<String, Object> {
    private static final String KEY_CODE = "code";
    private static final String KEY_DATA = "data";
    private static final String KEY_TIMESTAMP = "timestamp";
    private static final String KEY_MESSAGE = "message";

    private Ajax() {
        this.put("timestamp", System.currentTimeMillis());
    }

    public static Ajax success() {
        return success((Object)null, "请求成功");
    }

    public static Ajax success(Object data) {
        return success(data, "请求成功");
    }

    public static Ajax success(Object data, String message) {
        Ajax ajax = new Ajax();
        ajax.put("code", 200);
        ajax.put("data", data);
        ajax.put("message", message);
        return ajax;
    }

    public static Ajax fail(String message) {
        return fail(500, (Object)null, message);
    }

    public static Ajax fail(Object data, String message) {
        return fail(500, data, message);
    }

    public static Ajax fail(int code, Object data, String message) {
        Ajax ajax = new Ajax();
        ajax.put("code", code);
        ajax.put("data", data);
        ajax.put("message", message);
        return ajax;
    }

    public static Ajax fail(Exception e) {
        return fail(500, (Object)null, e.getMessage());
    }

    public static Ajax fail(int code, Exception e) {
        return fail(code, (Object)null, e.getMessage());
    }

    public Ajax setCode(int code) {
        this.put("code", code);
        return this;
    }

    public Ajax setData(Object data) {
        this.put("data", data);
        return this;
    }

    public Ajax setMessage(String message) {
        this.put("message", message);
        return this;
    }
}

